package com.atguigu.flink.chapter7;

import org.apache.flink.api.common.functions.ReduceFunction;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.windowing.assigners.TumblingProcessingTimeWindows;
import org.apache.flink.streaming.api.windowing.time.Time;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2020/12/22 15:11
 */
public class Flink06_Chapter7_WindowAll {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(2);


        env
          .socketTextStream("hadoop162", 9999)
          .windowAll(TumblingProcessingTimeWindows.of(Time.seconds(10)))
          .reduce(new ReduceFunction<String>() {
              @Override
              public String reduce(String value1, String value2) throws Exception {
                  return value1 + ":" + value2;
              }
          })
          .print();
        env.execute();
    }
}
